﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace StudentDefinition
{
    class Student : ICloneable, IComparable<Student>
    {
        public StudentPrivateInfo StudentPrivateInfo { get; set; }
        public Faculty Faculty { get; set; }
        public University University { get; set; }
        public Specialty Specialty { get; set; }

        public Student(StudentPrivateInfo studentPrivateInfo,
                       Faculty faculty,
                       University university,
                       Specialty specialty)
        {
            this.StudentPrivateInfo = studentPrivateInfo;
            this.Faculty = faculty;
            this.University = university;
            this.Specialty = specialty;
        }

        public int CompareTo(Student other)
        {
            if (this.StudentPrivateInfo.ToString().CompareTo(other) > 0)
            {
                return 1;
            }
            else if (this.StudentPrivateInfo.ToString().CompareTo(other) < 0)
            {
                return -1;
            }
            else
            {
                return 0;
            }
        }

        public object Clone()
        {
            StudentPrivateInfo newStudentPrivateInfo = (StudentPrivateInfo)this.StudentPrivateInfo.Clone();
            Student clondedStudent = new Student(newStudentPrivateInfo, this.Faculty, this.University, this.Specialty);
            return clondedStudent;
        }

        public override int GetHashCode()
        {
            unchecked
            {
                int result = 17;
                result = result * 23 +
                         ((StudentPrivateInfo != null) ? this.StudentPrivateInfo.GetHashCode() : 0);
                result = result * 23 + this.Faculty.GetHashCode();
                result = result * 23 + this.University.GetHashCode();
                result = result * 23 + this.Specialty.GetHashCode();
                return result;
            }
        }

        public override bool Equals(object obj)
        {
            Student temp = obj as Student;
            if (temp == null) return false;
            return this.Equals(temp);
        }

        public bool Equals(Student value)
        {
            return Equals(this.StudentPrivateInfo, value.StudentPrivateInfo) &&
                   this.Faculty.Equals(value.Faculty) &&
                   this.University.Equals(value.University) &&
                   this.Specialty.Equals(value.Specialty);
        }

        public override string ToString()
        {
            string result = this.StudentPrivateInfo.ToString() + Faculty + University + Specialty;
            return result;
        }
    }
}
